namespace JHT.EFMigrationTest.ClassLibrary1.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddProcUpdateAndInsertAndDelete : DbMigration
    {
        public override void Up()
        {
            CreateStoredProcedure(
                "dbo.ClassInfo_Insert",
                p => new
                    {
                        ClassName = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"INSERT [dbo].[ClassInfo]([ClassName])
                      VALUES (@ClassName)
                      
                      DECLARE @Id bigint
                      SELECT @Id = [Id]
                      FROM [dbo].[ClassInfo]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[ClassInfo] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            CreateStoredProcedure(
                "dbo.ClassInfo_Update",
                p => new
                    {
                        Id = p.Long(),
                        ClassName = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"UPDATE [dbo].[ClassInfo]
                      SET [ClassName] = @ClassName
                      WHERE ([Id] = @Id)"
            );
            
            CreateStoredProcedure(
                "dbo.ClassInfo_Delete",
                p => new
                    {
                        Id = p.Long(),
                    },
                body:
                    @"DELETE [dbo].[ClassInfo]
                      WHERE ([Id] = @Id)"
            );
            
            CreateStoredProcedure(
                "dbo.Students_Insert",
                p => new
                    {
                        AssignedClassId = p.Long(),
                        StudentName = p.String(maxLength: 50, unicode: false),
                        Gender = p.Int(),
                        FamilyAddress = p.String(maxLength: 50, unicode: false),
                        ContactTelphoe = p.String(maxLength: 20, unicode: false),
                        BirthDate = p.DateTime(),
                        Height = p.Decimal(precision: 18, scale: 2),
                        Weight = p.Decimal(precision: 6, scale: 2),
                    },
                body:
                    @"INSERT [dbo].[Students]([AssignedClassId], [StudentName], [Gender])
                      VALUES (@AssignedClassId, @StudentName, @Gender)
                      
                      DECLARE @Id bigint
                      SELECT @Id = [Id]
                      FROM [dbo].[Students]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      INSERT [dbo].[StudentsDetails]([Id], [FamilyAddress], [ContactTelphoe], [BirthDate], [Height], [Weight])
                      VALUES (@Id, @FamilyAddress, @ContactTelphoe, @BirthDate, @Height, @Weight)
                      
                      SELECT t0.[Id]
                      FROM [dbo].[Students] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            CreateStoredProcedure(
                "dbo.Students_Update",
                p => new
                    {
                        Id = p.Long(),
                        AssignedClassId = p.Long(),
                        StudentName = p.String(maxLength: 50, unicode: false),
                        Gender = p.Int(),
                        FamilyAddress = p.String(maxLength: 50, unicode: false),
                        ContactTelphoe = p.String(maxLength: 20, unicode: false),
                        BirthDate = p.DateTime(),
                        Height = p.Decimal(precision: 18, scale: 2),
                        Weight = p.Decimal(precision: 6, scale: 2),
                    },
                body:
                    @"UPDATE [dbo].[Students]
                      SET [AssignedClassId] = @AssignedClassId, [StudentName] = @StudentName, [Gender] = @Gender
                      WHERE ([Id] = @Id)
                      
                      UPDATE [dbo].[StudentsDetails]
                      SET [FamilyAddress] = @FamilyAddress, [ContactTelphoe] = @ContactTelphoe, [BirthDate] = @BirthDate, [Height] = @Height, [Weight] = @Weight
                      WHERE ([Id] = @Id)
                      AND @@ROWCOUNT > 0"
            );
            
            CreateStoredProcedure(
                "dbo.Students_Delete",
                p => new
                    {
                        Id = p.Long(),
                    },
                body:
                    @"DELETE [dbo].[StudentsDetails]
                      WHERE ([Id] = @Id)
                      
                      DELETE [dbo].[Students]
                      WHERE ([Id] = @Id)
                      AND @@ROWCOUNT > 0"
            );
            
            CreateStoredProcedure(
                "dbo.StudentsAddress_Insert",
                p => new
                    {
                        StudentsAddressId = p.Long(),
                        Address = p.String(maxLength: 50, unicode: false),
                        City = p.String(maxLength: 50, unicode: false),
                        ZipCode = p.Int(),
                        Province = p.String(maxLength: 50, unicode: false),
                        Country = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"INSERT [dbo].[StudentsAddress]([StudentsAddressId], [Address], [City], [ZipCode], [Province], [Country])
                      VALUES (@StudentsAddressId, @Address, @City, @ZipCode, @Province, @Country)"
            );
            
            CreateStoredProcedure(
                "dbo.StudentsAddress_Update",
                p => new
                    {
                        StudentsAddressId = p.Long(),
                        Address = p.String(maxLength: 50, unicode: false),
                        City = p.String(maxLength: 50, unicode: false),
                        ZipCode = p.Int(),
                        Province = p.String(maxLength: 50, unicode: false),
                        Country = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"UPDATE [dbo].[StudentsAddress]
                      SET [Address] = @Address, [City] = @City, [ZipCode] = @ZipCode, [Province] = @Province, [Country] = @Country
                      WHERE ([StudentsAddressId] = @StudentsAddressId)"
            );
            
            CreateStoredProcedure(
                "dbo.StudentsAddress_Delete",
                p => new
                    {
                        StudentsAddressId = p.Long(),
                    },
                body:
                    @"DELETE [dbo].[StudentsAddress]
                      WHERE ([StudentsAddressId] = @StudentsAddressId)"
            );
            
            CreateStoredProcedure(
                "dbo.TeacherInfo_Insert",
                p => new
                    {
                        TeacherName = p.String(maxLength: 50, unicode: false),
                        TeacherType = p.Int(),
                        ComlextType_Province = p.String(),
                        ComlextType_Street = p.String(),
                        Nation = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"INSERT [dbo].[TeacherInfo]([TeacherName], [TeacherType], [ComlextType_Province], [ComlextType_Street], [Nation])
                      VALUES (@TeacherName, @TeacherType, @ComlextType_Province, @ComlextType_Street, @Nation)
                      
                      DECLARE @Id bigint
                      SELECT @Id = [Id]
                      FROM [dbo].[TeacherInfo]
                      WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()
                      
                      SELECT t0.[Id]
                      FROM [dbo].[TeacherInfo] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[Id] = @Id"
            );
            
            CreateStoredProcedure(
                "dbo.TeacherInfo_Update",
                p => new
                    {
                        Id = p.Long(),
                        TeacherName = p.String(maxLength: 50, unicode: false),
                        TeacherType = p.Int(),
                        ComlextType_Province = p.String(),
                        ComlextType_Street = p.String(),
                        Nation = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"UPDATE [dbo].[TeacherInfo]
                      SET [TeacherName] = @TeacherName, [TeacherType] = @TeacherType, [ComlextType_Province] = @ComlextType_Province, [ComlextType_Street] = @ComlextType_Street, [Nation] = @Nation
                      WHERE ([Id] = @Id)"
            );
            
            CreateStoredProcedure(
                "dbo.TeacherInfo_Delete",
                p => new
                    {
                        Id = p.Long(),
                    },
                body:
                    @"DELETE [dbo].[TeacherInfo]
                      WHERE ([Id] = @Id)"
            );
            
            CreateStoredProcedure(
                "dbo.Books_Insert",
                p => new
                    {
                        BookNo = p.String(maxLength: 30, unicode: false),
                        Edition = p.Int(),
                        BookName = p.String(maxLength: 50, unicode: false),
                        BookAuthor = p.String(maxLength: 50, unicode: false),
                    },
                body:
                    @"INSERT [dbo].[Books]([BookNo], [Edition], [BookName], [BookAuthor])
                      VALUES (@BookNo, @Edition, @BookName, @BookAuthor)
                      
                      SELECT t0.[MyGUID], t0.[TimeStamp]
                      FROM [dbo].[Books] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[BookNo] = @BookNo AND t0.[Edition] = @Edition"
            );
            
            CreateStoredProcedure(
                "dbo.Books_Update",
                p => new
                    {
                        BookNo = p.String(maxLength: 30, unicode: false),
                        Edition = p.Int(),
                        BookName = p.String(maxLength: 50, unicode: false),
                        BookAuthor = p.String(maxLength: 50, unicode: false),
                        BookAuthor_Original = p.String(maxLength: 50, unicode: false),
                        MyGUID = p.Guid(),
                        TimeStamp_Original = p.Binary(maxLength: 8, fixedLength: true, storeType: "rowversion"),
                    },
                body:
                    @"UPDATE [dbo].[Books]
                      SET [BookName] = @BookName, [BookAuthor] = @BookAuthor
                      WHERE (((([BookNo] = @BookNo) AND ([Edition] = @Edition)) AND (([BookAuthor] = @BookAuthor_Original) OR ([BookAuthor] IS NULL AND @BookAuthor_Original IS NULL))) AND (([TimeStamp] = @TimeStamp_Original) OR ([TimeStamp] IS NULL AND @TimeStamp_Original IS NULL)))
                      
                      SELECT t0.[TimeStamp]
                      FROM [dbo].[Books] AS t0
                      WHERE @@ROWCOUNT > 0 AND t0.[BookNo] = @BookNo AND t0.[Edition] = @Edition"
            );
            
            CreateStoredProcedure(
                "dbo.Books_Delete",
                p => new
                    {
                        BookNo = p.String(maxLength: 30, unicode: false),
                        Edition = p.Int(),
                        BookAuthor_Original = p.String(maxLength: 50, unicode: false),
                        TimeStamp_Original = p.Binary(maxLength: 8, fixedLength: true, storeType: "rowversion"),
                    },
                body:
                    @"DELETE [dbo].[Books]
                      WHERE (((([BookNo] = @BookNo) AND ([Edition] = @Edition)) AND (([BookAuthor] = @BookAuthor_Original) OR ([BookAuthor] IS NULL AND @BookAuthor_Original IS NULL))) AND (([TimeStamp] = @TimeStamp_Original) OR ([TimeStamp] IS NULL AND @TimeStamp_Original IS NULL)))"
            );
            
        }
        
        public override void Down()
        {
            DropStoredProcedure("dbo.Books_Delete");
            DropStoredProcedure("dbo.Books_Update");
            DropStoredProcedure("dbo.Books_Insert");
            DropStoredProcedure("dbo.TeacherInfo_Delete");
            DropStoredProcedure("dbo.TeacherInfo_Update");
            DropStoredProcedure("dbo.TeacherInfo_Insert");
            DropStoredProcedure("dbo.StudentsAddress_Delete");
            DropStoredProcedure("dbo.StudentsAddress_Update");
            DropStoredProcedure("dbo.StudentsAddress_Insert");
            DropStoredProcedure("dbo.Students_Delete");
            DropStoredProcedure("dbo.Students_Update");
            DropStoredProcedure("dbo.Students_Insert");
            DropStoredProcedure("dbo.ClassInfo_Delete");
            DropStoredProcedure("dbo.ClassInfo_Update");
            DropStoredProcedure("dbo.ClassInfo_Insert");
        }
    }
}
